﻿using B.S.DataBase.MyProject.Domain.Procurements;
using B.S.DataBase.MyProject.Domain.Sales;
using B.S.DataBase.MyProject.ErrorCode;
using B.S.DataBase.MyProject.Infrastructure.Interface;
using MediatR;
using T.E.ERP.Write.API.Applicantions.Command.SalesCommand;

namespace T.E.ERP.Write.API.Applicantions.CommandHandler.SalesCommandHandler
{
    /// <summary>
    /// 修改退货通知单命令处理方法
    /// </summary>
    public class Udpreturn_notice_mainCommandHandler:IRequestHandler<Udpreturn_notice_mainCommand,APIResult<object>>
    {

        /// <summary>
        /// 退货通知单的仓储接口
        /// </summary>
        private readonly IBaseRepository<return_notice_main> rRepo;
        /// <summary>
        /// 构造方法
        /// </summary>
        /// <param name="iRepo"></param>
        public Udpreturn_notice_mainCommandHandler(IBaseRepository<return_notice_main> rRepo)
        {
            this.rRepo = rRepo;
        }
        /// <summary>
        /// 处理方法
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        public Task<APIResult<object>> Handle(Udpreturn_notice_mainCommand request, CancellationToken cancellationToken)
        {
            APIResult<object> result = new APIResult<object>();
            var list = rRepo.GetAll().Result.Where(x => x.notice_id == request.notice_id).FirstOrDefault();
            list.notice_id = request.notice_id;
            list.document_code = request.document_code;
            list.document_date = request.document_date;
            list.customer_name = request.customer_name;
            list.document_status = request.document_status;
            var obj = rRepo.Update(list).Result;
            if (obj > 0)
            {
                result.Code = APIEnum.修改成功;
                result.Msg = APIEnum.修改成功.ToString();
                result.data = obj;
            }
            else
            {
                result.Code = APIEnum.修改失败;
                result.Msg = APIEnum.修改失败.ToString();
            }
            return Task.FromResult(result);
        }



    }


}
